package geo.com.geosdkdemo.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import geo.com.geosdk.GeoManage;
import geo.com.geosdkdemo.R;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private RelativeLayout parent;
    private LinearLayout llEquipmentCommunicationSetup;
    private LinearLayout llRoverSetup;
    private LinearLayout llBaseSetup;
    private LinearLayout llStaticSetup;
    private LinearLayout llDebugSetup;
    private LinearLayout llLocation;
    private LinearLayout llDeviceInfo;
    private LinearLayout llHostRegister;
    private TextView tvVersionName;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }

    private void initData() {
        tvVersionName.setText(GeoManage.getInstance().getAppVersionName(this));
    }

    private void initView() {
        parent=findViewById(R.id.parent);
        llEquipmentCommunicationSetup=findViewById(R.id.ll_equipment_communication_setup);
        llRoverSetup=findViewById(R.id.ll_setup_rover);
        llBaseSetup=findViewById(R.id.ll_setup_base);
        llStaticSetup=findViewById(R.id.ll_setup_static);
        llDebugSetup=findViewById(R.id.ll_setup_debug);
        llLocation=findViewById(R.id.ll_location);
        llDeviceInfo=findViewById(R.id.ll_device_info);
        llHostRegister=findViewById(R.id.ll_host_register);
        tvVersionName=findViewById(R.id.tv_version_name);

        llEquipmentCommunicationSetup.setOnClickListener(this);
        llRoverSetup.setOnClickListener(this);
        llBaseSetup.setOnClickListener(this);
        llStaticSetup.setOnClickListener(this);
        llDebugSetup.setOnClickListener(this);
        llLocation.setOnClickListener(this);
        llDeviceInfo.setOnClickListener(this);
        llHostRegister.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(v==llEquipmentCommunicationSetup){
            Intent intent=new Intent(this,CommunicationSetupActivity.class);
            startActivity(intent);
        }else if(v==llRoverSetup){
            if(!GeoManage.getInstance().isConnectedBlueTooth()){
                Toast.makeText(this,"通讯未连接，请先进行通讯连接!", Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent=new Intent(this,RoverSetupActivity.class);
            startActivity(intent);
        }else if(v==llBaseSetup){
            if(!GeoManage.getInstance().isConnectedBlueTooth()){
                Toast.makeText(this,"通讯未连接，请先进行通讯连接!", Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent=new Intent(this,BaseSetupActivity.class);
            startActivity(intent);
        }else if(v==llStaticSetup){
            if(!GeoManage.getInstance().isConnectedBlueTooth()){
                Toast.makeText(this,"通讯未连接，请先进行通讯连接!", Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent=new Intent(this,StaticSetupActivity.class);
            startActivity(intent);
        }else if(v==llDebugSetup){
            if(!GeoManage.getInstance().isConnectedBlueTooth()){
                Toast.makeText(this,"通讯未连接，请先进行通讯连接!", Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent=new Intent(this,DebugSetupActivity.class);
            startActivity(intent);
        }else if(v==llLocation){
            if(!GeoManage.getInstance().isConnectedBlueTooth()){
                Toast.makeText(this,"通讯未连接，请先进行通讯连接!", Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent=new Intent(this,SatelliteLocateInformationActivity.class);
            startActivity(intent);
        }else if(v==llDeviceInfo){
            if(!GeoManage.getInstance().isConnectedBlueTooth()){
                Toast.makeText(this,"通讯未连接，请先进行通讯连接!", Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent=new Intent(this,DeviceInformationActivity.class);
            startActivity(intent);
        }else if(v==llHostRegister){
            if(!GeoManage.getInstance().isConnectedBlueTooth()){
                Toast.makeText(this,"通讯未连接，请先进行通讯连接!", Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent=new Intent(this,HostRegisterActivity.class);
            startActivity(intent);
        }
    }

}
